
#include <bits/stdc++.h>

const int INF = 0x3f3f3f3f;
const int N = 1e6 + 10;
using namespace std;
int a[N],n,m;

int ans(int l,int r)
{
	if(l == r) return a[l];
	int mid = l + r >> 1;
	int sum = 0,x = -INF,y = -INF;
	
	for(int i = mid;i>=l;i--)sum += a[i],x = max(x,sum);
	sum = 0;
	for(int i = mid+1;i <= r;i++)sum += a[i],y = max(y,sum);
	return max(max(ans(l,mid),ans(mid+1,r)),x+y);
}
void slove()
{
	cin >> n;
	for(int i =1;i <= n;i++)cin >> a[i];
	cout << max(0,ans(1,n));
}
int main() {
	int T = 1;
	//cin >> T;
	while(T--)slove();



	return 0;
}

